

function generateAndCheck()
{
  const numbers = [];
  let count = 0;

  for (var i = 1; i <= 6; i++) {
    
    var inputId = "num" + i; 
    var inputValue = document.getElementById(inputId).value;
    var duplicate = false;

    console.log(inputValue);

    for (var j = 0; j < numbers.length; ++j)
    {
      if (inputValue == numbers[j])
      duplicate = true;
    }
    if (duplicate) {
    alert("No duplicate Numbers!!!");
    for (var i = 6; i >= 0; i--) {
      document.getElementById("num" + i).value = "";
    }
     return 0;
    }
    else if (inputValue > 0 && inputValue < 41 && !numbers.includes(inputValue)) {
    numbers.push(Number(inputValue));
    }

    else {
      alert("Please reenter numbers, must be from 1-40 and no repeats!");
      for (var i = 6; i >= 0; i--) {
        document.getElementById("num" + i).value = "";
      }
      break;
    }
  
  }
   
  var yourResultLabel = document.getElementById("numberLabel");
  yourResultLabel.innerHTML = "Your Numbers " + numbers.join(", ");
  
  var randomNumbers = [];
  

  while (randomNumbers.length < 6){
    var randomNumber = Math.floor(Math.random() * 40) + 1;
    var found = false;

    for(var i = 0; i < randomNumbers.length; ++i) {
      if (randomNumber == randomNumbers[i])
      found = true;
   }
   if (!found)
      randomNumbers.push(randomNumber);
      
  }

  var randomResultLabel = document.getElementById("randomLabel");
  randomResultLabel.innerHTML = "Winning Number: " + randomNumbers.join(", ");
  
  var winningNumbers = [];
 
  if (numbers.length === 6)
{
 for (let i = 0; i < 6; i++) {
  for (let j = 0; j < 6; j++) {
    if (numbers[i] == randomNumbers[j]) {
      winningNumbers.push(numbers[i]);
      ++count;
    }
  }
 }
}

else
{
alert("Please re-enter numbers, must be from 1-40 and no repeats!");
}

alert("How many winning numbers you enter: " + count);

if (count === 0) {
  var results = "Sorry no winnings, play again. "; 
  
  var resultLabel = document.getElementById("resultLabel");
  resultLabel.innerHTML = results;
  }

else if (count === 1 || count === 2) {
var results = "Sorry no winnings, play again. "; 
var resultLabel = document.getElementById("resultLabel");
resultLabel.innerHTML = results + "Matching winning numbers: " + winningNumbers.join(", ");
}

else if (count === 3) {
  var results = "Nice won 5 big bucks! "; 
var resultLabel = document.getElementById("resultLabel");
resultLabel.innerHTML = results + "Winning Numbers " + winningNumbers.join(", ");
}

else if (count === 4) {
  var results = "Enjoy your 50 big ones!! "; 
var resultLabel = document.getElementById("resultLabel");
resultLabel.innerHTML = results + "Winning Numbers " + winningNumbers.join(", ");
}

else if (count === 5) {
  var results = "100 BABY!! "; 
var resultLabel = document.getElementById("resultLabel");
resultLabel.innerHTML = results + "Winning Numbers " + winningNumbers.join(", ");
}

else if (count === 6) {
  var results = "JACKPOT BABY!!!! $100,000!!!! ";
  var jackpotgif = document.getElementById('jackpot');
  jackpotgif.style.display = "block";

  var resultLabel = document.getElementById("resultLabel");
resultLabel.innerHTML = results + "Winning Numbers " + winningNumbers.join(", ");
}


}


